#region LicenseHeader

// Copyright 2012 The Trustees of Indiana University.  All rights reserved.
// 
// The Indiana University licenses this file to you under the Apache License, 
// Version 2.0 (the "License"); you may not use this file except in compliance 
// with the License.  You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
// See the License for the specific language governing permissions and 
// limitations under the License.
// 
// @author Thilina Gunarathne (tgunarat@indiana.edu)

#endregion

#region

using System;

#endregion

namespace NAligner
{
    public enum SequenceType
    {
        Protein,

        Nucleic
    }

    /// <summary>
    ///   A basic (nucleic or protein) sequence. It's a wrapper to <c>string</c> .
    /// </summary>
    /// <remarks>
    ///   The <see cref="Sequence" /> can be parsed if encoded with <a href="http://www.ncbi.nlm.nih.gov/BLAST/fasta.html">FASTA</a> .
    /// </remarks>
    [Serializable]
    public class Sequence
    {
        #region Members

        /// <summary>
        ///   List of amino acids
        /// </summary>
        private string _residues;

        /// <summary>
        ///   Sequence description.
        /// </summary>
        private string description;

        /// <summary>
        ///   Sequence id.
        /// </summary>
        private string id;

        /// <summary>
        ///   Sequence type.
        /// </summary>
        private SequenceType type = SequenceType.Protein;

        #endregion

        /// <summary>
        ///   Constructor
        /// </summary>
        public Sequence()
        {
        }

        /// <summary>
        ///   Constructor
        /// </summary>
        public Sequence(string sequence, string id, string description, SequenceType type)
        {
            _residues = sequence;
            this.id = id;
            this.description = description;
            this.type = type;
        }

        public char this[int residueIndex]
        {
            get { return _residues[residueIndex]; }
        }

        /// <summary>
        ///   Returns the sequence id
        /// </summary>
        public string Label
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        ///   Returns the sequence description
        /// </summary>
        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        /// <summary>
        ///   Returns the sequence type (nucleic or protein)
        /// </summary>
        public SequenceType Type
        {
            get { return type; }
            set { type = value; }
        }

        /// <summary>
        ///   Gets or sets the amino acid sequence
        /// </summary>
        public string Residues
        {
            get { return _residues; }
            set { _residues = value; }
        }

        public int Length
        {
            get { return _residues.Length; }
        }

        /// <summary>
        ///   Returns a subsequence
        /// </summary>
        /// <param name="index"> start index </param>
        /// <param name="length"> length of subsequence </param>
        /// <returns> subsequence </returns>
        public string Subsequence(int index, int length)
        {
            return _residues.Substring(index, (index + length) - (index));
        }
    }
}